#include <iostream>
#include <sstream>
#include <windows.h>
#include <string>

std::string w_to_utf8(const std::wstring wide_str)
{
    int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide_str.c_str(), (int)wide_str.size(), nullptr, 0, nullptr, nullptr) + 2;
    std::string utf8_str(size_needed, 0);
    WideCharToMultiByte(CP_UTF8, 0, wide_str.c_str(), (int)wide_str.size(), &utf8_str[0], size_needed, nullptr, nullptr);
    return utf8_str;
}

int main()
{
    // 设置控制台为 UTF-8
    UINT originalCP = GetConsoleOutputCP();
    std::cout << originalCP << std::endl;
    SetConsoleOutputCP(CP_UTF8);
    originalCP = GetConsoleOutputCP();
    std::cout << originalCP << std::endl;
    std::wstringstream wss;
    int a = 100;
    std::wstring name = L"张三";

    wss << L"c:\\windows\\"
        << a
        << L"\\abc.doc\\"
        << name;

    std::cout << w_to_utf8(wss.str()) << std::endl;

    return 0;
}